package com.seven.webhook.controller;


import cn.hutool.core.util.StrUtil;
import com.gs.cd.cloud.common.ApiResult;
import com.seven.webhook.config.mybatis.SpecialCharactersInterceptor;
import com.seven.webhook.model.MonitorRule;
import com.seven.webhook.service.MonitorRuleService;
import com.seven.webhook.utils.specification.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author seven
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/webhook/monitorRule")
public class MonitorRuleController extends
        AbstractController<MonitorRule, MonitorRuleService> {


    /**
     * 开启告警
     */
    @GetMapping("alert/{id}")
    public ApiResult alert(@PathVariable String id) {
        MonitorRule monitorRule = new MonitorRule();
        monitorRule.setId(id);
        monitorRule.setIsAlert(true);
        boolean b = iService.saveOrUpdate(monitorRule);
        return b ? ApiResult.success() : ApiResult.error();
    }

    /**
     * 关闭告警
     */
    @GetMapping("unalert/{id}")
    public ApiResult unalert(@PathVariable String id) {
        MonitorRule monitorRule = new MonitorRule();
        monitorRule.setId(id);
        monitorRule.setIsAlert(false);
        boolean b = iService.saveOrUpdate(monitorRule);
        return b ? ApiResult.success() : ApiResult.error();
    }
}

